package com.example.administrator.netchess;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class ListAdapter extends BaseAdapter{

    private Context context;
    private ArrayList<ListItem> arrayList;

    public ListAdapter (Context context,ArrayList<ListItem> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
        LayoutInflater inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = new ViewHolder();
        if (null==convertView){
              convertView = View.inflate(context,R.layout.room_list_item,null);
            viewHolder.room_text = (TextView) convertView.findViewById(R.id.room_list_text);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        ListItem item = arrayList.get(position);

        viewHolder.room_text.setText("房间号："+item.getRoom_id()+"  "+"房间名："+item.getRoom_name()+"  "+"选手数："+item.getPlayer_number());

        return convertView;
    }

    public class ViewHolder {
        public TextView room_text;
    }


}
